// import { tr } from 'element-plus/es/locales.mjs'
import { defineStore } from 'pinia'
import { login } from '@/api/menu/index.ts'

export const useMessageStore = defineStore('message', {
  state: () => ({
    message: 'Hello World',
    loginStatus:false,
    routerInit:false,
    isCollapsexx:false,
  }),
  getters: {
    fullMessage: (state) => `The message is "${state.message}".`,
  },
  actions: {
    
    async getMenu(): Promise<String>{
      return new Promise((resolve)=>{
        const menu=[{
          "url":"/user",
          "menuName":"ddd",
          "icon":"ddd",
          "menuType":"dd",
          "children":"{}"
        }];

        resolve(menu)
      })
    },

    async login(userName: string, password: string): Promise<boolean> {
      return new Promise((resolve) => {
        const loginParamsxx = {
          username: 'test',
          password: 'test',
          hospitalId:""
        }
        login(loginParamsxx).then((r) => {
          console.log('xx获取菜单====', r.data)
        })
        this.loginStatus=true
        this.routerInit=true
      
      // 登录操作并处理用户信息
      setTimeout(() => {
        // 这里的 this 是当前的 Store 实例
        resolve(true)
      }, 10)
       })
    },

    // 异步更新 message
    async updateMessage(newMessage: string): Promise<string> {
      return new Promise((resolve) => {
        setTimeout(() => {
          // 这里的 this 是当前的 Store 实例
          this.message = newMessage
          resolve('Async done.')
        }, 3000)
      })
    },
    // 同步更新 message
    updateMessageSync(newMessage: string): string {
      // 这里的 this 是当前的 Store 实例
      this.message = newMessage
      return 'Sync done.'
    },
  },persist:true
})
